#include<bits/stdc++.h>
using namespace std;
int a[100005],c[100005],b[100005];
int d[25][100005];
int x[10];
int ans[25][100005];
int idx[25];
int main()
{
	freopen("arena.in","r",stdin);
	freopen("arena.out","w",stdout);
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=m;i++) cin>>c[i];
	int mul=1,k=0;
	while(mul<n) mul*=2,k++;
	mul/=2;
	for(int i=1;i<=k;i++)
	{
		for(int j=1;j<=mul;j++) cin>>d[i][j];
		mul/=2;
	}
	int t;
	cin>>t;
	while(t--){
		cin>>x[0]>>x[1]>>x[2]>>x[3];
		for(int i=1;i<=n;i++) b[i]=a[i]^(x[i%4]);
		cout<<0<<endl;
	}
	return 0;
}
